/* @(#)ManufactureDown.java   
 *
 * Project: GS-1
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li    2006-7-7     新增
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.autotask;

import java.io.DataInputStream;
import java.io.IOException;
import java.net.URL;

import com.hitrust.gs.business.GSFileUploadProcessor;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.GSSystemConfigurator;
import com.hitrust.gs.util.date.DateUtil;
import com.hitrust.gs.util.exception.GSException;

/**
 * 
 */
public class ManufactureDown {
    
    public void doDown(){
        DataInputStream dis = null;
        try {            
            GSLogWriter.info ("Begin to Down Manufacture Data... ");
            
            String tDay=DateUtil.getNextUpDay(-1);
            //文件下载
            String Name="/" + GSSystemConfigurator.getParam("gs.purcode") + "_Product_"+tDay+".xls";
            URL url = new URL(GSSystemConfigurator.getParam("gs.down.schema")+"://"+GSSystemConfigurator.getParam("gs.down.host")+":"+GSSystemConfigurator.getParam("gs.down.port")+"/"+GSSystemConfigurator.getParam("gs.down.fullpath")+Name);

            dis = new DataInputStream(url.openStream());
            
            //FormFile tFileName=f2;
            String tResult="";
            //UserBean tUserBean = (UserBean)aForm.getSession().getAttribute(BaseConstants.LOGIN);
            try{
                //导入产品信息
                tResult=GSFileUploadProcessor.batchImportManufacture(dis,"");
            }catch(GSException e){
                GSLogWriter.error(e.getMessage());  
            }   
            //从返回的值中取得失败和成功的数据
            String tSuccess= tResult.split("-")[0];
            String tFail= tResult.split("-")[1];
            String tOutputPath = tResult.split("-")[2];
            if(Integer.parseInt(tFail)>0){
                GSLogWriter.error("Fail down output Manufacture path: " + tOutputPath);
                GSLogWriter.error("Fail import Manufacture count: " + tFail);                
            }
            GSLogWriter.info("Success import Manufacture count: " + tSuccess);
        }
        catch (Exception ex) {
            GSLogWriter.error("下载产品信息时出错!");
            GSLogWriter.error(ex.getMessage());
        }
        finally{
            if(dis != null){
                try {
                    dis.close();
                }
                catch (IOException e) {
                    
                    e.printStackTrace();
                }
            }
        }
        
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    }

}
